package com.jack.leetcode.eachproblem_2020;

public class 不同路径 {

    public static void main(String[] args) {
        uniquePaths(3, 2);
        System.out.println(uniquePaths(7, 3));
    }

    public static int uniquePaths(int m, int n) {
        if(m == n && m == 1){
            return 1;
        }
        int[][] dp = new int[m][n];
        for(int i = 1;i < m;i++){
            dp[i][0] = 1;
        }
        for(int j = 1;j < n;j++){
            dp[0][j] = 1;
        }
        for(int i = 1;i < m;i++){
            for(int j = 1;j < n;j++){
                dp[i][j] = (i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0);
            }
        }
        return dp[m - 1][n - 1];
    }
}
